package blaha.genalg.run;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import org.apache.log4j.Logger;

import blaha.genalg.beans.Board;
import blaha.genalg.graphgen.JoinBasicPoints;
import blaha.genalg.graphgen.JoinToCreateSecondLevel;
import blaha.genalg.graphgen.PlacePointsToCreateFirstLevel;
import blaha.genalg.graphgen.RemoveDisconnectedPoints;
import blaha.genalg.methods.ReadAllProperties;
import blaha.genalg.output.GraphML2XML;
import blaha.logging.Log;

public class TownOverBoard {

	private static final Logger log = Log.getLoggerMoje();

	// calculate board
	static Board board = null;

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub

		ReadAllProperties settings;
		try {
			SimpleDateFormat dateFormat =
				new SimpleDateFormat("ss.SSS");
			dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
			long time_start = System.currentTimeMillis();
			
			long time_setti_start = System.currentTimeMillis();
			settings = new ReadAllProperties();
			log.debug(dateFormat.format(new Date(System.currentTimeMillis()-time_setti_start))+" settings read");
			// calculate board

			long time_mem_start = System.currentTimeMillis();
			board = new Board(settings);
			long time_memA_start = System.currentTimeMillis()-time_mem_start;
			log.debug(dateFormat.format(new Date(time_memA_start))+" memory object create");
			// putpoints
			long time_points_start = System.currentTimeMillis();
			board = new PlacePointsToCreateFirstLevel().Create(board, settings);
			log.debug(dateFormat.format(new Date(System.currentTimeMillis()-time_points_start))+" place points");

			long time_join_start = System.currentTimeMillis();
			board = new JoinBasicPoints().Join(board, settings); 
			long time_joinE_start = System.currentTimeMillis();
			log.debug(dateFormat.format(new Date(time_joinE_start-time_join_start))+" basic join");
			board = new RemoveDisconnectedPoints().Purge(board, settings);
			//log.debug(dateFormat.format(System.currentTimeMillis()) + " remove");

			long time_SLjoin_start = System.currentTimeMillis();
			board = new JoinToCreateSecondLevel().JoinSecondLevel(board, settings);
			log.debug(dateFormat.format(new Date(System.currentTimeMillis()-time_SLjoin_start))+" SL join");

			long time_graph_start = System.currentTimeMillis();
			GraphML2XML.Create(board, settings);
			log.debug(dateFormat.format(new Date(System.currentTimeMillis()-time_graph_start))+" write to GraphML file");
			
			//end calculation
			long time_end = System.currentTimeMillis();
			log.info(dateFormat.format(new Date(time_end-time_start))+"   all");
			
			log.debug(dateFormat.format(new Date(time_joinE_start-time_join_start))+" basic join");
			



			//log.debug(cal.getTime());

			// new PrintMatrice(board);

			// test case
			// new TCPrintConnections(board);

		} catch (Throwable e) {
			log.error("Error ocured", e);
		}
	}
}
